function Object(name) {
  this.name = name;
  this.cell = null;
  this.cell_index = 0;
  this.img = null;
  this.x = 0;
  this.y = 0;
  this.dx = 0;
  this.dy = 0;
  this.sx = 0;
  this.sy = 0;
  this.moving = false;
  this.actions = [];
};


/**
 * Moves this Object to the specified Cell.
 *
 */
Object.prototype.moveto = function(cell) {
  // Don't continue if already moving
  if (this.moving)
    return;
  
  this.moving = true;
  
  // Remove this Creature from being an object of its current Cell
  if (this.cell != null)
    this.cell.removeObject(this);
  
  // Add this Creature as an object belonging to the target Cell
  cell.addObject(this);
  
  // Remember where we are coming from and going to
  this.dx = cell.x - this.x;
  this.dy = cell.y - this.y;
  this.sx = this.x;
  this.sy = this.y;
  
  // Start the movement animation
  ex1 = new Animator();
  ex1.addSubject(this);
  ex1.play();
};


/**
 * Teleports this Object to the specified Cell.
 *
 */
Object.prototype.setLocation = function(cell) {
  // Remove this Creature from being an object of its current Cell
  if (this.cell != null)
    this.cell.removeObject(this);
  
  // Add this Creature as an object belonging to the target Cell
  cell.addObject(this);
  
  this.x = cell.x;
  this.y = cell.y;
  
  ooc.redraw();
};


/**
 * Callback for Animator animation interval.
 *   
 * @param value
 * 	Tween value for this iteration in the range [0.0, 1.0] 
 */
Object.prototype.setState = function(value) {
  this.x = this.sx + this.dx * value;
  this.y = this.sy + this.dy * value;
  ooc.redraw();
}


/**
 * Callback for Animator end of animation.
 *
 */
Object.prototype.onComplete = function() {
  this.moving = false;
}


/**
 * Adds an Action to this Object.
 *
 */
Object.prototype.addAction = function(action) {
  this.actions[this.actions.length] = action;
}


/**
 * Removes an Action from this Object.
 *
 */
Object.prototype.removeAction = function(action) {
  for (var i = 0; i < this.actions.length; i++)
    if (this.actions[i] == action)
      this.actions.remove(i, i);
}


/**
 * Removes all Actions from this Object.
 *
 */
Object.prototype.clearActions = function() {
  this.actions = [];
}


/**
 * Shows this Object on the Objects list.
 *
 */
Object.prototype.showActions = function(el) {
  var obj = document.createElement('div');
  obj.setAttribute('class', 'object');
  var head = document.createElement('div');
  head.setAttribute('class', 'objecthd');
  var img = document.createElement('img');
  img.setAttribute('src', this.img.src);

  head.appendChild(img);
  head.appendChild(document.createTextNode(this.name));
  obj.appendChild(head);
  el.appendChild(obj);
  
  
  for (var i = 0; i < this.actions.length; i++)
    this.actions[i].showAction(obj);
}


/**
 * Draws this Objects image
 *
 */
Object.prototype.draw = function(ctx) {
  ctx.drawImage(this.img, this.x, this.y);
};
